/**
 *====================================================
 * 文件名称: FinanceAuditLogServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceContactsEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;

@Implements(FinanceContactsService.class)
public class FinanceContactsServiceImpl implements FinanceContactsService {

	@Override
	public Long createFinanceContactsEntity(FinanceContactsEntity entity) {
		entity.setCreateDateTime(new Date());
		PersistUtil.insert(entity);
		return entity.getId();
	}

	@Override
	public List<FinanceContactsEntity> inquireFinanceContactsList(Long accountId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceContactsEntity.class);
		criteria.add(Restrictions.eq("accountId", accountId));
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria);
	}
	
	@Override
	public void deleteFinanceContactsEntity(Long accountId,Long contactsId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceContactsEntity.class);
		criteria.add(Restrictions.eq("accountId", accountId));
		criteria.add(Restrictions.eq("contactsId", contactsId));
		List<FinanceContactsEntity> list=PersistUtil.get(criteria);
		if(list!=null&&list.size()>0){
			if(list.get(0)!=null&&list.get(0).getId()!=null)
				PersistUtil.delete(FinanceContactsEntity.class, list.get(0).getId());
		}
		
	}

}
